package com.nursinghome.user.controller;

import com.nursinghome.admin.service.MedicalStaffService;
import com.nursinghome.bean.MedicalStaff;
import com.nursinghome.bean.RespBean;
import com.nursinghome.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/user/medical")
public class UserMedicalController {
    @Autowired
    private MedicalStaffService medicalStaffService;
    @GetMapping()
    public RespBean empInfo(@RequestHeader(value = "token", required = false) String token ,
                            Integer serviceId) {
        Map<String, Object> map = JwtUtils.parseJwtToMap(token);
        Long jwtEid =  new Long(String.valueOf(map.get("eid")));
        if (jwtEid == null) {
            return RespBean.error("令牌信息不正确");
        }
        List<MedicalStaff> list = medicalStaffService.selectByEid(jwtEid, serviceId);
        return RespBean.ok("",list);
    }
    @GetMapping("/{mid}")
    public RespBean selectByMid(@PathVariable("mid") Integer mid) {
        MedicalStaff medicalStaff = medicalStaffService.selectByMid(mid);
        return RespBean.ok("",medicalStaff);
    }
}
